package com.sgb.kjwl.viewmodel.manage;

import androidx.core.util.Pair;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.manage.CompanyTradesDetailEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.view.ui.activity.manage.CompanyTradesDetailActivity;
import com.sgb.kjwl.view.ui.activity.manage.ShopInfoForCompanyTradesActivity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopInfoActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CompanyTradesDetailModel extends BaseViewModel {

    CompanyTradesDetailActivity companyTradesDetailActivity;

    public CompanyTradesDetailModel(CompanyTradesDetailActivity companyTradesDetailActivity) {
        this.companyTradesDetailActivity = companyTradesDetailActivity;
    }

    public void getCompanyTradesDetail(Map<String,Object> id){
        DialogHelper.showProgressDialog(companyTradesDetailActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getCompanyTradesDetail(id).enqueue(new Callback<BaseEntity<CompanyTradesDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<CompanyTradesDetailEntity>> call, Response<BaseEntity<CompanyTradesDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(companyTradesDetailActivity, "暂无数据");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    companyTradesDetailActivity.getCompanyTradesDetail(response.body().getData());
                } else {
                    MToast.showToast(companyTradesDetailActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<CompanyTradesDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }

    public void clickFor(String id,String companyNo){
        WebsiteInfoActivity.start(companyTradesDetailActivity,companyNo,1);
      //  ActivityJump.jumpToActivity(companyTradesDetailActivity, ShopInfoForCompanyTradesActivity.class, Pair.create("id",id),Pair.create("position",5),Pair.create("childPosition",0),Pair.create("companyNo",companyNo));
    }
}
